<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
<title>通告管理--通告列表</title>
<link rel="stylesheet" href="css/luyan/luyan.css" type="text/css"></link>
 <link rel="stylesheet" href="easyui/themes/icon.css" type="text/css"></link>
	 <link rel="stylesheet" href="easyui/themes/default/easyui.css" type="text/css"></link>
	 <script type="text/javascript" src="easyui/jquery-1.8.3.js"></script>
	 <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
<script type="text/javascript">
	$(function(){
	$.post("folder/findAllUser.do",
		function(data){
			user=data;
			init();
		},"json");
				
		 	
	});
	function init(){
			$("#div2").dialog({closed:true});
  			$("#div3").dialog({closed:true});
	  		$("#dg").datagrid({
	  			url:"announce/findAll.do",
	  			striped:true,	  			
	  			rownumbers:true,
	  			title:"通告列表",
	  			pagination:true,
	  			pageList:[10,20,50],
	  			columns:[[{
	  				title:"标题",
	  				field:"title",
	  				width:200,
	  				align:"right",
	  				formatter:function(value,row){
	  					return "<a  href='announce/findById.do?id="+row.id+"'>"+value+"</a>";
	  				}
	  			},{
	  				title:"发布人",
	  				field:"userid",
	  				width:150,
	  				align:"center",
	  				formatter:function(value){
	  					for(var i=0;i<user.length;i++){
	  						if(value==user[i].id){
	  							return user[i].name;
	  						}
	  					}
	  				}
	  			},{
	  				title:"发布时间",
	  				field:"releasedate",
	  				width:100,
	  				align:"right",
	  				
	  				formatter:date
	  			},{
	  				title:"操作",
	  				field:"id",
	  				width:100,
	  				align:"right",
	  				formatter:function (value,row,index){
						return "<a onclick='update("+row.id+")' href='javascript:void(0)'>修改</a>&nbsp;&nbsp;&nbsp;<a onclick='del("+row.id+")' href='javascript:void(0)'>删除</a>";
						}	  				
	  			}]],
	  			toolbar:[{text:"新增",iconCls:"icon-add",handler:function(){
	  				add();
	  			}}]		
	  		});
	  		
	  		$("#div3").dialog({
		    title: "修改",
		    width: 400,
		    height: 350,
		    closed: true,
		    buttons:[{
				text:"修改",
				handler:function(){
					var data ="id="+$("#id1").val()+
					"&title="+$("#title1").val()+
					"&content="+$("#content1").val()+
	  				"&releasedate="+$("#releasedate1").val()+
	  				"&userid="+$("#userid").val()+
	  				"&createdate="+$("#createdate1").html();
					$.get("announce/update.do",data,function(data){
								alert(data);
								$("#div3").dialog("close");
								$("#dg").datagrid("reload");
							},"text");  	
				}
			},{
				text:"取消",
				handler:function(){
					$("#div3").dialog("close");
				}
			}]
		});
	
	} ; 	
	
		function date(value){
			return value.year+1900+"-"
			+(value.month+1)+"-"+value.date;
		}
		function date1(){
		var date1 = new Date();
		var tt = ""+date1.getFullYear()+"-";
		tt+=(date1.getMonth()+1)+"-";
		tt+=date1.getDate()+" ";
		tt+=date1.getHours()+":";
		tt+=date1.getMinutes()+":";
		tt+=date1.getSeconds();
		return tt;
		}
		function add(){
		$("#sp").html(date1());
		$("#div2").dialog({
  			title:"新增",
  			width:400,
  			heigeht:200,
  			closed:false,
  			modal:true,
  			buttons:[{text:"保存",
  					handler:function(){
  						var data = "title="+$("#title").val()+
  						"&content="+$("#content").val()+
  						"&releasedate="+$("#releasedate").val()+
  						"&userid="+$("#userid").val()+
  						"&createdate="+$("#sp").html();
  						
  							$.post(
  								"announce/add.do",
  								data,
  								function(data){
  								alert(data);
  									$("#div2").dialog("close");
  									$("#dg").datagrid("reload");
  								},
  								"text"
  							);
  					}
  					},
  					{text:"取消",
  					handler:function(){
  							$("#div2").dialog("close");
  						}
  					}]
  		});
		}
		
		function update(value){
			
			$("#div3").dialog("open");	
			$.post("announce/findByid.do","id="+value,function(data){
			$.post("users/findById.do","id="+data.userid,function(data){
  				$("#userid1").html(data.name);
  			},"json");
  				$("#id1").val(value);
  				$("#title1").val(data.title);
  				$("#content1").val(data.content);
  				var re= date(data.releasedate);
  				var re= date(data.createdate);
  				$("#createdate1").html(re);
  				$("#releasedate1").val(re);
  			},"json");
		};
		
		function del(value){
			$.messager.confirm("提示框", "你确定要删除吗?",function(r){
				if(r){
					var data = "id="+value;
					$.post(
		  				"announce/delete.do",
		  				data,
		  				function(data){
		  				alert(data);
		  				$("#dg").datagrid("reload");
		  				
		  				},
		  				"text"
		  			);
				}
			});
		};
</script>

</head>

<body style="height: 800px" id="mainbody">
	<p style="margin-bottom: 20px"><img src="css/chenwenjing/img/icons/contacts.png" width="32px" height="32px"/>&nbsp;&nbsp;<span>我的桌面</span></p>    
	    <table id="dg" ></table>
	<div class="content" >
			<!-- 新增通告 -->
			<div id="div2">
				标题：<input id="title" name="title"   type="text"/><br/><br/>
				内容：<input id="content" name="content"  type="text"/><br/><br/>
				发布时间：<input id="releasedate" name="releasedate"  type="text"/><label>日期格式为：xxxx-xx-xx</label><br/><br/>
				发布人：${user.name}<br/><br/>
				创建时间：<span id="sp"></span>
			</div>
			<!-- 修改通告 -->
			<div id="div3">
				<input type="hidden" name="announce.id" id="id1">
				标题：<input id="title1" name="title1"   type="text"/><br/><br/>
				内容：<input id="content1" name="content1"  type="text"/><br/><br/>
				发布时间：<input id="releasedate1" name="releasedate1"  type="text"/><br/><br/>
				发布人：<span id="userid1"></span><br/><br/>
				创建时间：<span id="createdate1"></span>
			</div>
			<input type="hidden" value="${user.id}" id="userid" />
			<input type="hidden" value="${user.name}" id="userid" />
	</div>	
</body>
</html>
